package com.kaishengit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.Goal;
import com.kaishengit.entity.Project;
import com.kaishengit.service.GoalService;
import com.kaishengit.util.web.ServletUtil;

public class SaveNewGoalServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		GoalService goalService = new GoalService();
		Project project = (Project) request.getSession().getAttribute("curr_project"); 
		int projectId = project.getId(); 
		String title = request.getParameter("title");
		String description = request.getParameter("description");
		
		Goal goal = new Goal();
		goal.setTitle(title);
		goal.setDescription(description);
		goal.setProjectId(projectId);
		goalService.save(goal);

		ServletUtil.redirect(response, "goal.jspx");
	}

}
